package com.airbnb.epoxy;

import ohos.agp.colors.RgbColor;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;

import java.util.Random;

/**
 * StyleElement
 *
 * @author twx1009780
 * @since 2021-01-27
 */
public class StyleElement {
    public static final int DEFAULT_COLOR = Color.WHITE.getValue();

    /**
     * method getStyleElement is used to convert in color to ShapeElement
     *
     * @param color {@link Color}
     * @return ShapeElement
     */
    public static ShapeElement getStyleElement(int color) {
        if (color == 0) {
            color = DEFAULT_COLOR;
        }
        ShapeElement style = new ShapeElement();
        style.setRgbColor(RgbColor.fromArgbInt(color));
        return style;
    }

    /**
     * method getRandomColor is used to generate random colors for used.
     *
     * @return ShapeElement
     */
    public static ShapeElement getRandomColor() {
        Random obj = new Random();
        int randNum = obj.nextInt(0xffffff + 1);
        int color = Color.getIntColor(String.format("#%06x", randNum));
        ShapeElement style = new ShapeElement();
        style.setRgbColor(RgbColor.fromArgbInt(color));
        return style;
    }
}
